import { IApiRes, IBannerItem, IGoodsItem, IHotGoods } from '@/types/data'
import { bannerApi, newGoodsList, hotGoodsList } from '@/api/home'
import { defineStore } from 'pinia'
export default defineStore('home', {
  state: () => {
    return {
      bannerList: [] as IBannerItem[],
      newGoodsList: [] as IGoodsItem[],
      hotGoodsList: [] as IHotGoods[]
    }
  },
  actions: {
    // 轮播图
    async getBannerList(): Promise<void> {
      const res = await bannerApi()
      console.log(res.data.result);
      this.bannerList = res.data.result
    },
    // 新鲜好物
    async getNewGoodsList() {
      const res = await newGoodsList()
      console.log(res.data.result);
      this.newGoodsList = res.data.result
    },
    // 人气推荐
    async getHotGoodsList() {
      const res = await hotGoodsList()
      this.hotGoodsList = res.data.result
    }
  }
})